﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EasyStep.Attributes;
using EasyStep.TestExecution.Data;
using EasyStep.TestExecution.Interfaces;
using OpenQA.Selenium;

namespace EasyStep.TestActions.Actions.Functions
{
    [TestAction(typeof(Functions._Functions), "Remove Cookies", RequireScreenShot = true, RequireLocator = false, RequireData = false)]
    public class ClearCookies : ITestAction<IWebDriver>
    {
        public void Execute(IWebDriver browser, TestStepResult data, IExecuteDataContext context)
        {
            browser.Manage().Cookies.DeleteAllCookies();
        }
    }

    [TestAction(typeof(Functions._Functions), "Remove Cookie", RequireScreenShot = true, RequireLocator = true, RequireData = false)]
    public class ClearCookiesByName : ITestAction<IWebDriver>
    {
        public void Execute(IWebDriver browser, TestStepResult data, IExecuteDataContext context)
        {
            browser.Manage().Cookies.DeleteCookieNamed(data.Locator);
        }
    }

    [TestAction(typeof(Functions._Functions), "Set Cookie", RequireScreenShot = false, RequireLocator = true, RequireData = true)]
    public class SetCookies : ITestAction<IWebDriver>
    {
        public void Execute(IWebDriver browser, TestStepResult data, IExecuteDataContext context)
        {
            var r=browser.Manage().Cookies.GetCookieNamed(data.Locator);
            if (r != null)
                browser.Manage().Cookies.DeleteCookieNamed(data.Locator);
            
            browser.Manage().Cookies.AddCookie(new Cookie(data.Locator, data.Data));
            
        }
    }
}
